package com.eunion.core.common.excel;

import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.annotation.JsonProperty.Access;

public final class ExcelImportWarning {

    public enum Severity {
        NORMAL, CRITICAL, BLOCKER;
    }

    public enum Operation {
        SKIP, ABORT;
    }

    public enum RootCause {
        EMPTY_VALUE, UNEXPECTED_VALUE, DATA_NOT_FOUND, DATA_ARLEADY_EXISTED;
    }

    @JsonProperty(access = Access.READ_ONLY)
    private String sheetName;

    @JsonProperty(access = Access.READ_ONLY)
    private int column;

    @JsonProperty(access = Access.READ_ONLY)
    private String columnAlias;

    @JsonProperty(access = Access.READ_ONLY)
    private Severity severity;

    @JsonProperty(access = Access.READ_ONLY)
    private Operation operation;

    @JsonProperty(access = Access.READ_ONLY)
    private RootCause rootCause;

    public static ExcelImportWarning abort(String sheetName, int column, String columnAlias, RootCause rootCause) {
        ExcelImportWarning w = new ExcelImportWarning();
        w.sheetName = sheetName;
        w.column = column;
        w.columnAlias = columnAlias;
        w.operation = Operation.ABORT;
        w.severity = Severity.BLOCKER;
        w.rootCause = rootCause;
        return w;
    }

    public static ExcelImportWarning skip(String sheetName, int column, String columnAlias, RootCause rootCause) {
        ExcelImportWarning w = new ExcelImportWarning();
        w.sheetName = sheetName;
        w.column = column;
        w.columnAlias = columnAlias;
        w.operation = Operation.SKIP;
        w.severity = Severity.CRITICAL;
        w.rootCause = rootCause;
        return w;
    }

    public static ExcelImportWarning normal(String sheetName, int column, String columnAlias, RootCause rootCause) {
        ExcelImportWarning w = new ExcelImportWarning();
        w.sheetName = sheetName;
        w.column = column;
        w.columnAlias = columnAlias;
        w.operation = Operation.SKIP;
        w.severity = Severity.NORMAL;
        w.rootCause = rootCause;
        return w;
    }

    private ExcelImportWarning() {
        super();
    }

    public String getSheetName() {
        return sheetName;
    }

    public int getColumn() {
        return column;
    }

    public String getColumnAlias() {
        return columnAlias;
    }

    public Severity getSeverity() {
        return severity;
    }

    public Operation getOperation() {
        return operation;
    }

    public RootCause getRootCause() {
        return rootCause;
    }

    @Override
    public String toString() {
        return "ImportWarning [sheetName=" + sheetName + ", column=" + column + ", columnAlias=" + columnAlias
                + ", severity=" + severity + ", operation=" + operation + ", rootCause=" + rootCause + "]";
    }

}
